<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册界面</title>
    <link rel="stylesheet" href="css/logincommon.css">
    <link rel="stylesheet" href="css/login.css">
</head>


<body>
<div class="nav">
    <img src="pic/logo2.jpg" alt="">
     <span class="blog-title">五子棋对战</span>
</div>
<div class="container-login">
    <div class="login-dialog">
        <h3>注册</h3>
        <div class="row">
            <span>用户名</span>
            <input type="text" name="username" id="username" required placeholder="请输入用户名">
        </div>
        <div class="row">
            <span>密码</span>
            <input type="password" name="password" id="password" required placeholder="请输入密码">
        </div>
        <div class="row">
            <button id="submit" onclick="register(event)">注册</button>
        </div>
        <div class="row">
            <span>已有账号？</span>
            <a href="gobang_login.html">前往登录</a>
        </div>
    </div>
</div>
<script src="js/jquery.min.js"></script>
<script>
    function register(event) {
        event.preventDefault();
        $.ajax({
            type:'post',
            url:'user/register',
            data:{
                "userName": $("#username").val(),
                "password": $("#password").val()
            },
            success:function(body) {
                if(body == 0) {
                    console.log("注册成功");

                    alert('注册成功')
                    location.assign('/gobang_login.html');
                }else if(body == 2){
                    alert('用户名已存在')
                }else{
                    alert('用户名或密码为空')
                }
            }
        });
    }
</script>
</body>
</html>